
from django.db.models import F, Value
from django.db.models.signals import post_save, pre_delete
from django.dispatch import receiver

from .models import ContractProduct, Product, StockRecord


# @receiver(post_save, sender=StockRecord)
# def alert_user(sender, instance, created, **kwargs) -> None:  # noqa: ANN003, ARG001
#     if created:
#         if instance.stock_code == "oms":
#             ContractProduct.objects.filter(id=instance.contract_product.id).update(oms_balance=F("oms_balance") - instance.incoming_weight)
#             product = ContractProduct.objects.filter(id=instance.contract_product.id).first()
#             product.warehouse = product.warehouse + instance.incoming_weight
#             product.save()
#         if instance.stock_code == "ob":
#             ContractProduct.objects.filter(id=instance.contract_product.id).update(ob_balance=F("ob_balance") - instance.incoming_weight)
#             product = ContractProduct.objects.filter(id=instance.contract_product.id).first()
#             product.warehouse = product.warehouse + instance.incoming_weight
#             product.save()
#         if instance.stock_code == "pd":
#             ContractProduct.objects.filter(id=instance.contract_product.id).update(pd_balance=F("pd_balance") - instance.incoming_weight)
#             product = ContractProduct.objects.filter(id=instance.contract_product.id).first()
#             product.warehouse = product.warehouse + instance.incoming_weight
#             product.save()
